<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.lsl.endworkvol.entity.Activity" %>
<%@ page import="com.lsl.endworkvol.entity.SignUpNote" %>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/pintuer.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/volunteer.css">
    <script src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script src="<%=request.getContextPath()%>/js/pintuer.js"></script>
</head>
<body>
<form method="post" action="search_activities" id="listform">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder">活动列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
        <div class="padding border-bottom">
            <ul class="search" style="padding-left:10px;">
                <li>搜索：</li>

                <li>
                    <input type="text" placeholder="搜索：活动标题" name="title" class="input" style="width:250px; line-height:17px;display:inline-block" />
                    <input type="text" placeholder="搜索：活动地点" name="position" class="input" style="width:250px; line-height:17px;display:inline-block" />
                    <select name="acti_status" class="input" style="width:200px; line-height:17px;display:inline-block">
                        <option value="">搜索：活动状态</option>
                        <option value="未开始">未开始</option>
                        <option value="报名中">报名中</option>
                        <option value="报名已结束">报名已结束</option>
                        <option value="进行中">进行中</option>
                        <option value="已结束">已结束</option>
                    </select>
                    <input type="checkbox" name="showCheckOutOnly" value="1" /> 仅显示已签到
                    <a href="javascript:void(0)" class="button border-main icon-search" onclick="changeSearch()" > 搜索</a></li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th>活动名</th>
                <th>活动描述</th>
                <th>活动地点</th>
                <th>负责人</th>
                <th>活动开始时间</th>
                <th>活动结束时间</th>
                <th>状态</th>
                <th>人数</th>
                <th>签到情况</th>
                <th>操作</th>
            </tr>
            <%--使用JSTL标签库的迭代标签输出userlist集合的元素--%>
            <%
                Date currentDate = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                List<SignUpNote> notesList = (List<SignUpNote>) pageContext.getAttribute("notesList");
            %>
            <c:forEach var="item" varStatus="looper" items="${activitiesList}" >
                <%
                    String status = "未知";
                    Activity activity = (Activity) pageContext.getAttribute("item");
                %>
                <tr>
                    <td>${item.title}</td>
                    <td>${item.caption}</td>
                    <td>${item.position}</td>
                    <td>${leadersNameList[looper.count-1]}</td>
                    <td><%=dateFormat.format(activity.getStartTime())%></td>
                    <td><%=dateFormat.format(activity.getEndTime())%></td>
                    <td>
                        <%
                            if (activity.getStartTime().before(currentDate) && activity.getEndTime().after(currentDate)) {
                                status = "进行中";
                            } else if (activity.getSignUpEndTime().after(currentDate) && activity.getSignUpStartTime().before(currentDate)) {
                                status = "报名中";
                            } else if (activity.getStartTime().after(currentDate)) {
                                status = "未开始";
                            } else if (activity.getEndTime().before(currentDate)) {
                                status = "已结束";
                            }
                            pageContext.setAttribute("status", status);
                        %>
                        ${status}
                    </td>
                    <td>${item.volunteerCount}/${item.volunteerMaxCount}</td>
                    <td>${notesCheckOutStatusList[looper.count-1]}</td>
                    <td>
                        <div class="button-group">
                            <c:if test="${status=='进行中' and notesCheckOutStatusList[looper.count-1] == '未签到'}">
                                <a class="button border-main" href="activity_checkout/${notesIdList[looper.count-1]}"><span class="icon-check"></span> 签到</a>
                            </c:if>
                            <c:if test="${status == '报名中'}">
                                <a class="button border-red" href="activity_exit/${notesIdList[looper.count-1]}" ><span class="icon-times"></span> 退出活动</a>
                            </c:if>
                        </div>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <!--分页-->
        <%-- <div class="pagelist">
         <a href="">上一页</a> <span class="current">1</span>
         <a href="">2</a><
         a href="">3</a><a href="">下一页</a><a href="">尾页</a> </div> --%>
    </div>
</form>
<script type="text/javascript">
function changeSearch(){
    $("#listform").submit();
}
</script>
</body>
</html>